/*
 * @Author: your name
 * @Date: 2021-01-12 16:15:10
 * @LastEditTime: 2021-01-14 15:41:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \carlist\src\store\index.js
 */
import { createStore,applyMiddleware,combineReducers} from "redux";
import thunk from "redux-thunk"


function getReducers(){
    //自动导入所有的文件;
    let files = require.context('./reducers',true,/\.js$/);
    console.log(files);
    //获取文件的内容
    return files.keys().reduce((pre,item)=>{
        let key=item.match(/\.\/(\w+)\.js$/)[1];
        console.log(key)
        pre[key] = files(item).default;
        return pre;
    },{})
}

/**
 * combineReducers ----redux的辅助函数-----把一个reducer函数作为value的object;
 * 合并成一个大的reducer函数;
 * 合并后的reducer 调用createstore;
 * 就是产生一个整体的函数;
 */
// combineReducers({
//     cars:reducer函数,
//     sd
// })

   let reducer = combineReducers(getReducers())

   const store = createStore(reducer,applyMiddleware(thunk));


   export default store;








